package ssn.common.util;

import java.util.List;

import ssn.servicearea.vo.ServiceAreaVO;
import egovframework.rte.fdl.string.EgovStringUtil;

public class Util {

	public static String decode(String unicode) throws Exception {
		StringBuffer str = new StringBuffer();

		char ch = 0;
		for (int i = unicode.indexOf("\\u"); i > -1; i = unicode.indexOf("\\u")) {
			ch = (char) Integer.parseInt(unicode.substring(i + 2, i + 6), 16);
			str.append(unicode.substring(0, i));
			str.append(String.valueOf(ch));
			unicode = unicode.substring(i + 6);
		}
		str.append(unicode);

		return str.toString();
	}

	public static String encode(String unicode) throws Exception {
		StringBuffer str = new StringBuffer();

		for (int i = 0; i < unicode.length(); i++) {
			if (((int) unicode.charAt(i) == 32)) {
				str.append(" ");
				continue;
			}
			str.append("\\u");
			str.append(Integer.toHexString((int) unicode.charAt(i)));

		}

		return str.toString();

	}
	
	public static String[] getTelArray(String telNumInhyphen) {
		if(telNumInhyphen == null || telNumInhyphen.indexOf("-") == -1){
			return new String[]{"","",""};
		}
		String[] returnStringArray = telNumInhyphen.split("-");
		switch (returnStringArray.length) {
			case 0:	return new String[]{"","",""};
			case 1:	return new String[]{returnStringArray[0],"",""};
			case 2:	return new String[]{returnStringArray[0],returnStringArray[1],""};
			default: return returnStringArray;
		}
	}
	
	/**
     * 현장명 가져오기
     * @param serviceareaList
     * @param searchSerivceAreaKey
     * @return
     */
    public static String getServiceAreaName(List serviceareaList, String searchSerivceAreaKey){
    	String resultSheetName = "전체";
		if(EgovStringUtil.isNotEmpty(searchSerivceAreaKey)){
			for(int i=0;i<serviceareaList.size();i++){
				ServiceAreaVO serviceAreaVO = (ServiceAreaVO)serviceareaList.get(i);
				if(serviceAreaVO.getSsa_area_key().equals(searchSerivceAreaKey)){
					resultSheetName = serviceAreaVO.getSsa_area_name();
					break;
				}
			}
		}
    	return resultSheetName;
    }
}
